//上传图片
function uploadPic() {
    //创建formData对象
    var formData = new FormData();
    formData.append("file",$("#tripPic")[0].files[0]);
    //发送ajax
    $.ajax({
        url: "/upload/pic",
        data: formData,
        type: "post",
        dataType: "json",
        success: function (result) {
            if (result.code == 0){
                // alert(result.data.src)
                $("#img").attr("src",result.data.src);
                $("#hiddenPic").val(result.data.src);
                $("#picInfo").html("上传成功啦！").css("color","green");
            } else {
                alert(result.msg);
            }
        },
        error: function () {
            alert("您还没有选择图片！")
        },
        contentType: false,
        processData: false
    });
}

// 动态显示图片
function preview(file){
    if (file.files && file.files[0]){
        reader = new FileReader();
        reader.onload = function(evt){
            $("#img").attr("src",evt.target.result);
        }
        reader.readAsDataURL(file.files[0]);
    }

}